//
//  TouchIDCell.m
//  掌上宏力
//
//  Created by admin on 2017/7/13.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "TouchIDCell.h"

@interface TouchIDCell ()

@property (nonatomic,weak) UILabel *titLab;

@property (nonatomic,weak) UIImageView *iconView;

@end

@implementation TouchIDCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(5, 13, 24, 24)];
        [self.contentView addSubview:imgV];
        self.iconView = imgV;
        
        UILabel *titLab = [Factory createLabelWithFrame:CGRectMake(imgV.right+8, 0, 100, 50)];
        titLab.font = kFont(16);
        [self.contentView addSubview:titLab];
        self.titLab = titLab;

        UISwitch *st = [[UISwitch alloc] initWithFrame:CGRectMake(kScreenW-70, 5, 50, 40)];
        NSString *state = [[NSUserDefaults standardUserDefaults] valueForKey:@"touchIdState"];
        if ([state isEqualToString:@"YES"]) {
            [st setOn:YES];
        }else{
            [st setOn:NO];
        }
        [st addTarget:self action:@selector(touchSwitchChanged:) forControlEvents:UIControlEventValueChanged];
        [self.contentView addSubview:st];
        self.touchSwitch = st;
    }
    return self;
}
-(void)touchSwitchChanged:(UISwitch *)st{
    if (self.touchOn) {
        self.touchOn();
    }
}

-(void)touchSwitchOn:(touchSwitchOn)switchBlock{
    self.touchOn = switchBlock;
}
-(void)setDic:(NSDictionary *)dic{
    self.iconView.image = [UIImage imageNamed:dic[@"icon"]];
    self.titLab.text = dic[@"title"];
}

+(instancetype)cellWithTableView:(UITableView *)tableView{
    static NSString *cellId = @"touchid";
    TouchIDCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[TouchIDCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryNone;
    return cell;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
